<?php
/**
 * Helper DOM
 */
class DOM_Helper {
	
	/**
	 * Check if an DOM Element has a css class
	 */
	public static function hasClassName($elem, $classname) {
		$founded = false;
		if ($elem && $elem->hasAttribute("class")) {
			$css_classes = explode(" ", $elem->getAttribute("class"));
			if (in_array($classname, $css_classes)) {
				$founded = true;
			}
		}
		return $founded;
	}
	
	/**
	 * Get the next DOM Element sibling
	 */
	public static function getNextElementSibling($elem) {
		$e = $elem->nextSibling;
		while (!is_null($e) && $e->nodeType != XML_ELEMENT_NODE) {
			$e = $e->nextSibling;
		}
		
		return $e;
	}
	
	/**
	 * Get elements of a css class
	 */
	public static function getElementsByClassName($dom, $tag, $classname) {
		$elements = $dom->getElementsByTagName($tag);
		$results = array();
		foreach ($elements as $e) {
			if ($e->hasAttribute("class")) {
				$css_classes = explode(" ", $e->getAttribute("class"));
				if (in_array($classname, $css_classes)) {
					$results[] = $e;
				}
			}
		}
		return $results;
	}
}
?>